package com.shopx.auth.service.impl;


import com.shopx.auth.bean.SysUserCp;
import com.shopx.auth.dao.db1.SysUserCpDao;
import com.shopx.auth.model.SysUserCpModel;
import com.shopx.auth.service.ISysUserCpService;
import com.shopx.base.constants.ResultCodeEnum;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.service.ISysSeqService;
import com.shopx.cmm.DTO.PageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author lituo
 * @className: SysUserCp
 * @date 2023-05-23
 */
@Service
@Slf4j
public class SysUserCpServiceImpl implements ISysUserCpService {

    @Autowired
    private SysUserCpDao sysUserCpDao;

    @Resource
    private ISysSeqService sysSeqService;

    @Override
    public SysUserCpModel selectByPrimaryKey(SysUserCp sysUserCp) {
        if (sysUserCp == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        return sysUserCpDao.selectByPrimaryKey(sysUserCp);
    }

    @Override
    public int insertSelective(SysUserCp sysUserCp) {
        if (sysUserCp == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        int result = sysUserCpDao.insertSelective(sysUserCp);
        if (result != 1) {
            throw new ShopxException(ResultCodeEnum.DB_ERROR);
        }
        return result;
    }

    @Override
    public int updateByPrimaryKeySelective(SysUserCp sysUserCp) {
        if (sysUserCp == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        int result = sysUserCpDao.updateByPrimaryKeySelective(sysUserCp);
        if (result != 1) {
            throw new ShopxException(ResultCodeEnum.DB_ERROR);
        }
        return result;
    }

    @Override
    public int deleteByPrimaryKey(SysUserCp sysUserCp) {
        if (sysUserCp == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        int result = sysUserCpDao.deleteByPrimaryKey(sysUserCp);
        if (result != 1) {
            throw new ShopxException(ResultCodeEnum.DB_ERROR);
        }
        return result;
    }

    @Override
    public int selectCount(SysUserCpModel sysUserCp) {
        return sysUserCpDao.selectCount(sysUserCp);
    }

    @Override
    public List<SysUserCpModel> selectList(SysUserCpModel sysUserCp) {
        List<SysUserCpModel> list = sysUserCpDao.selectList(sysUserCp);
        return list;
    }

    @Override
    public PageDTO<SysUserCpModel> getListPage(SysUserCpModel sysUserCp) {
        if (sysUserCp == null) {
            throw new ShopxException(ResultCodeEnum.PAR_NULL);
        }
        PageDTO<SysUserCpModel> pageDTO = new PageDTO<SysUserCpModel>();
        pageDTO.setiTotalDisplayRecords(selectCount(sysUserCp));
        pageDTO.setData(selectList(sysUserCp));
        return pageDTO;
    }

}

